{% extends "base.html" %}

{% block content %}
<div class="admin-dashboard container">
    <div class="admin-header">
        <h1>用户管理</h1>
        <div class="header-actions">
            <a href="{{ url_for('admin.add_user') }}" class="btn">
                <i class="fas fa-user-plus"></i> 添加用户
            </a>
            <a href="{{ url_for('admin.index') }}" class="btn">返回首页</a>
        </div>
    </div>

    <div class="table-container card">
        <table class="admin-table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>用户名</th>
                    <th>邮箱</th>
                    <th>管理员</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for user in users.items %}
                <tr>
                    <td>{{ user.id }}</td>
                    <td>{{ user.username }}</td>
                    <td>{{ user.email }}</td>
                    <td>
                        <span class="status-badge {% if user.is_admin %}active{% endif %}">
                            {{ '是' if user.is_admin else '否' }}
                        </span>
                    </td>
                    <td class="action-buttons">
                        <a href="{{ url_for('admin.edit_user', id=user.id) }}" class="btn btn-sm">编辑</a>
                        <button class="btn btn-sm btn-danger delete-btn" data-id="{{ user.id }}" data-type="users">删除</button>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    {% if users.pages > 1 %}
    <div class="pagination">
        {% if users.has_prev %}
        <a href="{{ url_for('admin.manage_users', page=users.prev_num) }}" class="btn btn-sm">&laquo; 上一页</a>
        {% endif %}
        
        <span class="current-page">第 {{ users.page }} 页，共 {{ users.pages }} 页</span>
        
        {% if users.has_next %}
        <a href="{{ url_for('admin.manage_users', page=users.next_num) }}" class="btn btn-sm">下一页 &raquo;</a>
        {% endif %}
    </div>
    {% endif %}
</div>
{% endblock %}

{% block scripts %}
<script src="{{ url_for('static', filename='js/admin.js') }}"></script>
{% endblock %} 